<template>
  <el-dialog
    class="dialog"
    title="Rui Ning 10"
    v-dialogDrag
    :visible.sync="dialogVisible"
    width="800px"
    :modal="false"
    :modal-append-to-body="false"
    :append-to-body="false"
    :close-on-click-modal="false"
    @close="close"
    hiddenButton
  >
    <div class="detail-content">
      <video-player
        class="video-player vjs-custom-skin"
        ref="videoPlayer"
        :playsinline="true"
        :options="playerOptions"
      >
      </video-player>
    </div>
    <!-- 按钮列表 -->
    <div class="bottom-content">
      <div class="button-list">
        <el-button
          class="ele-button"
          size="mini"
          type="primary"
          @click="handleStart()"
        >
          开始
        </el-button>
        <el-button
          class="ele-button"
          size="mini"
          type="primary"
          @click="handleStop()"
        >
          停止
        </el-button>
        <el-button
          class="ele-button"
          size="mini"
          type="primary"
          @click="handlePhoto()"
        >
          截图
        </el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { videoPlayer } from "vue-video-player";
import "video.js/dist/video-js.css";
import "vue-video-player/src/custom-theme.css";
import "videojs-contrib-hls";
import { stopVideoUrl } from "@/api/video";

export default {
  components: { videoPlayer },
  data() {
    return {
      dialogVisible: false,
      data: {},
      playerOptions: {
        autoplay: false, // 如果true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 导致视频一结束就重新开始。
        preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: "zh-CN",
        aspectRatio: "16:9",
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        techOrder: ["html5"], // 兼容顺序
        html5: { hls: { withCredentials: false } },
        sources: [
          {
            // type: "application/x-mpegURL",
            // src: "https://live.cgtn.com/1000/prog_index.m3u8",
            // type: "video/mp4",
            // src: require("./shipin.mp4"),
            type: "application/x-mpegURL",
            src: "http://114.55.175.168:8002/live?app=live&stream=radar",
          },
        ],
        poster: "", //你的封面地址
        notSupportedMessage: "此视频暂无法播放，请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true, //全屏按钮
        },
      },
    };
  },
  methods: {
    open(row = {}) {
      this.data = row;
      this.dialogVisible = true;
      const data = "http://114.55.175.168:8002/live?app=live&stream=radarDemo";
      // getVideoUrl().then(({ data }) => {
        console.log("data: ", data);
        // this.playerOptions["sources"][0]["src"] = data.url;
        // this.$nextTick(() => {
        //   this.handleStart();
        // });
      // });
    },
    close() {
      stopVideoUrl().then(() => {});
      this.dialogVisible = false;
    },
    handleStart() {
      const player = this.$refs.videoPlayer.player;
      player.play();
    },
    handleStop() {
      const player = this.$refs.videoPlayer.player;
      player.pause();
    },
    handlePhoto() {
      const player = this.$refs.videoPlayer.player;
      player.pause();
    },
  },
};
</script>

<style lang="scss" scoped>
.dialog {
  &::v-deep .el-dialog__header {
    background-color: $base-theme-sub-color;
    padding: 15px 20px;
    .el-dialog__title {
      color: #fff;
    }
    .el-dialog__headerbtn {
      i:before {
        color: #fff;
      }
    }
  }
  .bottom-content {
    .button-list {
      text-align: right;
      margin-top: 20px;
    }
  }
}
</style>
